package com.example.service.impl;

import com.example.mapper.ApartmentMapper;
import com.example.pojo.Apartment;
import com.example.service.ApartmentService;
import com.example.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ApartmentServiceImpl implements ApartmentService {
    @Autowired
    private ApartmentMapper apartmentMapper;


    @Override
    public void add(Apartment apartment, HttpServletRequest request) {
        apartment.setIdU(JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class));
        apartmentMapper.add(apartment);
    }

    @Override
    public List<Apartment> getApartment(String name,Integer cuType, HttpServletRequest request) {
        Integer idU = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        List<Apartment> apartmentList=apartmentMapper.getApartment(name,cuType,idU);
        return apartmentList;
    }

    @Override
    public void delApartment(Integer id, HttpServletRequest request) {
        Integer idU = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        apartmentMapper.delApartment(id,idU);
    }

    @Override
    public Apartment getApartmentId(Integer id) {
        Apartment apartment=apartmentMapper.getApartmentId(id);
        return apartment;
    }

    @Override
    public void setApartment(Apartment apartment, HttpServletRequest request) {
        apartment.setIdU(JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class));
        apartmentMapper.setApartment(apartment);
    }

    @Override
    public List<Apartment> getApartmentIndex(String name, String location, String fitment, Double areaMin, Double areaMax, String roomType, Double priceMin, Double priceMax, String towards,String subway) {
        List<Apartment> list=apartmentMapper.getApartmentIndex(name,location,fitment,areaMin,areaMax,priceMin,priceMax,roomType,towards,subway);
        return list;
    }
}
